<template>
  <div>
    <ZgNewPage
      ref="page"
      :showInlineBtn="true"
      :uniqueName="uniqueName"
      :pageOpt="pageOpt"
      :headers="headers"
      :conditions="conditions"
      @search="onSearch"
      @filter="onFilter"
      @header="mergeHeader"
    >
      <template slot="columns">
        <a-table-column
          v-for="(h,i) in headers"
          :key="`column${i}`"
          :width="h.width===0 ? 'auto' : h.width"
          align="center"
          :title="h.label">
          <template slot-scope="record">
            <template v-if="h.code === 'compName'">
              <span style="color:#1890ff;">{{ record[h.code] }}</span>
            </template>
            <template v-else>
              {{ record[h.code] }}
            </template>
          </template>
        </a-table-column>
      </template>
      <template slot="thMode" slot-scope="scope">
        <a-row :gutter="10">
          <a-col :span="4" v-for="t in scope.list" :key="`thMode_${t.id}`">
            <a-card class="mb10">
              <div class="wfull h100 scroll">
                {{ t }}
              </div>
            </a-card>
          </a-col>
        </a-row>
      </template>
    </ZgNewPage>
  </div>
</template>
<script>
export default {
  data () {
    return {
      uniqueName: 'test',
      pageOpt: {
        showPageTitle: false,
        showConditionBtn: true,
        showHeaderConfig: true,
        showAttachBtn: false
      },
      conditions: [
        { code: 'birth', compType: '日期区间', label: '登录时间', defaultVal: ['', ''] },
        { code: 'name', compType: '单行文本', label: '账号', defaultVal: '', extra: { placeholder: '请输入账号' } },
        { code: 'name', compType: '单行文本', label: '姓名', defaultVal: '', extra: { placeholder: '请输入姓名' } }
      ],
      headers: [
        { code: '1', label: '账号', isShow: true, sort: 0 },
        { code: '2', label: '姓名', isShow: true, sort: 0 },
        { code: '3', label: '登录时间', isShow: true, sort: 0 },
        { code: '4', label: 'ip', isShow: true, sort: 0 },
        { code: '5', label: '状态', isShow: true, sort: 0 }
      ]
    }
  },
  methods: {
    search () {
      const pageRef = this.$refs.page
      if (pageRef) {
        pageRef.search()
      } else {
        setTimeout(() => {
          this.search()
        }, 50)
      }
    },
    onSearch (param) {
      const diyHeaders = localStorage.getItem(this.currentUser.username + '_diyHeader_' + this.uniqueName)
      if (diyHeaders) {
        this.mergeHeader(JSON.parse(diyHeaders))
      }
      // 加载表头
      const list = [
        { key: '1', id: '1', '1': 'jkdsjfd@jmjt', '2': '张三', '3': '2025-01-01 16 08:08', '4': '192.12.1.232', '5': '登录成功' }
    ]
      this.$refs.page.endSearch({
        total: list.length,
        list: list
      })
    },
    onFilter (f, param) {
    },
    mergeHeader (newHeaders) {
      if (!newHeaders) {
        return
      }
      this.headers = newHeaders.filter(t => {
        return t.isShow
      }).sort((a, b) => {
        return a.sort - b.sort
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
